package com.jxau.controller;

import Jama.Matrix;
import com.jxau.service.AlgorithmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import java.util.Set;

/**
 * @author lts
 * @create 2022-04-30 21:12
 */
@CrossOrigin
@Controller
public class AlgorithmController {

    @Autowired
    AlgorithmService algorithmService;

    @CrossOrigin
    @RequestMapping("/det")
    @ResponseBody
    public Double calculateDet(@RequestBody Map<String,String> map) {
        Double result = algorithmService.calculateDet(map.get("one"));
        return result;
    }

    @CrossOrigin
    @RequestMapping("/addMatrix")
    @ResponseBody
    public Matrix addMatrix(@RequestBody Map<String,String> map) {
        String matrix1 = map.get("one");
        String matrix2 = map.get("two");
        Matrix matrix = algorithmService.addMatrix(matrix1, matrix2);
        return matrix;
    }

    @CrossOrigin
    @RequestMapping("/mulMatrix")
    @ResponseBody
    public Matrix multipMatrix (@RequestBody Map<String,String> map){
        String matrix1 = map.get("one");
        String matrix2 = map.get("two");
        return algorithmService.multipMatrix(matrix1,matrix2);
    }

    @RequestMapping("/transposeMatrix")
    @ResponseBody
    public Matrix transposeMatrix(@RequestBody Map<String,String> map){
        return algorithmService.transposeMatrix(map.get("one"));
    }

    @RequestMapping("/inverseMatrix")
    @ResponseBody
    public Matrix inverseMatrix(@RequestBody Map<String,String> map){
        return algorithmService.inverseMatrix(map.get("one"));
    }

    @RequestMapping("/rankMatrix")
    @ResponseBody
    public Integer rankMatrix(@RequestBody Map<String,String> map){
        return algorithmService.rankMatrix(map.get("one"));
    }

    @RequestMapping("/eigMatrix")
    @ResponseBody
    public Set eigMatrix(@RequestBody Map<String,String> map){
        return algorithmService.eigMatrix(map.get("one"));
    }


}
